// 
// SoapTrace.Net - A soap message monitoring utility. 
// 
// Copyright (C) 2004 Matthew Ward
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Matthew Ward (mrward@users.sourceforge.net)
// 

using NUnit.Framework;
using System;
using WinPcap;

namespace WinPcap.Tests
{
	/// <summary>
	/// Tests the Packet class.
	/// </summary>
	[ TestFixture ]
	public class PacketTestFixture
	{
		/// <summary>
		/// The packet test fixture.
		/// </summary>
		private Packet m_Packet;

		/// <summary>
		/// Tests the raw hex dump functionality.
		/// </summary>
		[ Test ]
		public void RawHexDump( )
		{
			byte[ ] Bytes = new byte[ ] { 0x0, 0x45, 0xFF };

			string ExpectedRawHex = "0000  00 45 FF ";

			// Create raw hex string.

			m_Packet = new Packet( Bytes );

			Assert.AreEqual( ExpectedRawHex, 
				m_Packet.RawHex,
				"Unexpected raw hex string." );
		}

		/// <summary>
		/// Tests the raw hex dump functionality with an output that
		/// will spread over two lines.
		/// </summary>
		[ Test ]
		public void RawHexDumpOverTwoLines( )
		{
			byte[ ] Bytes = new byte[ ] 
				{ 
					0x00, 0x45, 0xFF, 0xEE, 0xAA, 0xBB, 0xCC, 0xDD,
					0x01, 0x45, 0xFF, 0xEE, 0xAA, 0xBB, 0xCC, 0xDD,
					0xFF, 0xEE, 0xDD, 0xBB, 0x01, 0x02, 0x03, 0x04,
					0x04, 0x03, 0x02, 0x01, 0xFF, 0xEE, 0xDD, 0xBB
				};

			string ExpectedRawHex = "0000  00 45 FF EE AA BB CC DD  01 45 FF EE AA BB CC DD \r\n";
			ExpectedRawHex += "0010  FF EE DD BB 01 02 03 04  04 03 02 01 FF EE DD BB ";

			// Create raw hex string.
			m_Packet = new Packet( Bytes );

			Assert.AreEqual( ExpectedRawHex, 
				m_Packet.RawHex,
				"Unexpected raw hex string." );
		}

	}
}
